package logic

import (
	"bw-renting/user-rpc/userclient"
	"context"
	"strconv"

	"bw-renting/api/internal/svc"
	"bw-renting/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserRegisterLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserRegisterLogic {
	return &UserRegisterLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// TODO: 用户注册
func (l *UserRegisterLogic) UserRegister(req *types.UserRegisterReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	d, _ := l.svcCtx.UserServer.UserRegister(l.ctx, &userclient.UserRegisterReq{
		Mobile: req.Mobile,
	})
	return &types.Data{
		Code:    int(d.Code),
		Message: d.Message,
		Data: map[string]string{
			"code": strconv.FormatInt(d.UserId, 10),
		},
	}, nil
}
